/**
 * Copyright(c) 2010 Ismole Co.Ltd.
 * All Right Reserved.
 */
package
{
	/**
	 * <p>项目名称: Ninja_New</p>
	 * <p>所属模块: 描述这个类属于哪一系统哪一模块</p>
	 * <p>实现功能: 描述该类实现了什么功能，尽可能详尽</p>
	 * <p>当前状态: 未完成</p>
	 * @author 杨邦庆
	 * @version 1.0
	 * @param arg[0]  arg[1] ...
	 */
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	[SWF(width="900",height="600", backgroundColor="#60A20C",frameRate="24")]
	public class poker extends Sprite
	{
		private var _startPoint:Point;
		private var r:Sprite = new Sprite();
		private var poke:CardType;
		public function poker()
		{
			_startPoint = new Point(0,0);
			poke = new CardType();
			this.addChild(poke);
			addChild(r);
			
			stage.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDownHandler);
			stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUp1);
		}
		
		private function onMouseUp1(evt:MouseEvent):void
		{
			stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMouseMoveHandler);
			var _mx:Number = mouseX <= poke.x? poke.x+5:mouseX;			
			var _pos1:Array=poke.getObjectsUnderPoint(_startPoint);
			var _pos2:Array=poke.getObjectsUnderPoint(new Point(_mx,_startPoint.y));
			var _pos3:Array=poke.getObjectsUnderPoint(new Point(_mx,mouseY));
			var _pos4:Array=poke.getObjectsUnderPoint(new Point(_startPoint.x,mouseY));
			var tempArray:Array = new Array();
			if (_pos1.length>0) {
				tempArray.push(_pos1[_pos1.length-1].parent);
			}
			if (_pos2.length>0) {
				tempArray.push(_pos2[_pos2.length-1].parent);
			}
			if (_pos3.length>0) {
				tempArray.push(_pos3[_pos3.length-1].parent);
			}
			if (_pos4.length>0) {
				tempArray.push(_pos4[_pos4.length-1].parent);
			}
			tempArray.sort(sortfunc);
			if (tempArray.length>0) {
				var k:uint=tempArray[0].x/20;
				if (tempArray.length==4 &&tempArray[0].x==tempArray[1].x&&tempArray[0].x==tempArray[2].x&&tempArray[0].x==tempArray[3].x) {
					{
						(poke.cardViewArr[0] as CardView).dispatchEvent(new MouseEvent(MouseEvent.CLICK));
					}
				} else {
					for (var i:uint=k; i<53; i++) {
						if (r.hitTestObject(poke.cardViewArr[i])) {
							(poke.cardViewArr[i] as CardView).dispatchEvent(new MouseEvent(MouseEvent.CLICK));
						}
					}
				}
			}
			
			r.graphics.clear();
		}
		
		private function sortfunc(a:Object,b:Object):Number {
			if (a.x>=b.x) {
				return 1;
			} else {
				return -1;
			}
		}
		
		private function onMouseDownHandler(evt:MouseEvent):void
		{
			_startPoint=new Point(mouseX,mouseY);
			stage.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMoveHandler);
		}
		
		private function onMouseMoveHandler(e:MouseEvent):void {
			r.graphics.clear();
			r.graphics.lineStyle(1,0x000000);
			r.graphics.drawRect(_startPoint.x,_startPoint.y,mouseX-_startPoint.x,mouseY-_startPoint.y);
		}
	}
}